home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / GOFER / gs / iomonad < prev   
Text File  |  1994-06-06  |  2KB  |  52 lines

  1. ------------------------------------------------------------------------------
  2. -- This file contains a Gofer implementation of Lazy state threads, as
  3. -- described in the PLDI '94 paper by John Launchbury and Simon Peyton
  4. -- Jones, using new Gofer primitives added in Gofer 2.30.
  5. --
  6. -- This file is included for the benefit of those interested in
  7. -- experimenting with the use of lazy functional state threads.
  8. -- You may expect to see changes to the definitions in this file,
  9. -- to track future proposals for monadic I/O in Haskell.
  10. --
  11. -- This file requires the standard, or cc prelude.
  12. -- You will not be able to use this file unless the version of Gofer that
  13. -- is installed on your machine has been compiled with the IO_MONAD flag
  14. -- set to 1.
  15. --
  16. -- Mark P Jones, 1994
  17. ------------------------------------------------------------------------------
  18.  
  19. module LazyStateThd( thenST, thenST_, returnST, newVar, readVar, WriteVar,
  20.              mutVarEq, getch, putchar, thenIO, seqST, putString,
  21.              getchar
  22.            ) where
  23.  
  24. infixr `thenST_`, `thenST`
  25.  
  26. primitive returnST "primSTReturn"   :: a -> ST s a
  27. primitive thenST   "primSTBind"     :: ST s a -> (a -> ST s b) -> ST s b
  28. primitive newVar   "primSTNew"      :: a -> ST s (MutVar s a)
  29. primitive readVar  "primSTDeref"    :: MutVar s a -> ST s a
  30. primitive writeVar "primSTAssign"   :: MutVar s a -> a -> ST s ()
  31. primitive mutvarEq "primSTMutVarEq" :: MutVar s a -> MutVar s a -> Bool
  32. primitive getch    "primIOGetch"    :: IO Char
  33. primitive putchar  "primIOPutchar"  :: Char -> IO ()
  34. primitive thenIO   "primIOBind"        :: ST s a -> (a -> ST s b) -> ST s b
  35.  
  36. instance Eq (MutVar s a) where (==) = mutvarEq
  37.  
  38. thenST_       :: ST s () -> ST s b -> ST s b
  39. p `thenST_` q  = p `thenST` \() -> q
  40.  
  41. seqST         :: [ST s ()] -> ST s ()
  42. seqST          = foldr thenST_ (returnST ())
  43.  
  44. putString     :: String -> IO ()
  45. putString      = seqST . map putchar
  46.  
  47. getchar = getch       `thenST` \c ->
  48.           putchar c   `thenST_`
  49.           returnST c
  50.  
  51. ------------------------------------------------------------------------------
  52.